<?php


namespace app\store\controller\shop;


use app\store\controller\Controller;
use app\common\model\Reservation as ReservationModel;
use app\store\model\store\Shop as ShopModel;
use app\store\model\store\shop\Coach as CoachModel;

class Reservation extends Controller
{
    public function index(){
        $model = new ReservationModel();
        $shop_user_id = $this->store['user']['shop_user_id'];
        $user_type = $this->store['user']['user_type'];
        $filter = [];
        if ($user_type == 2){
            //门店
            $filter['shop_id'] = $shop_user_id;
        }elseif ($user_type == 3){
            //教练
            $filter['coach_id'] = $shop_user_id;
        }
        $list = $model->getList(array_merge($filter,$this->request->param()));
        $coach = $this->coachList();
        $shopList = $this->shopList();
//        dump($list->toArray());die;
        $status = [
            0=>'待上课',
            1=>'开始上课',
            2=>'结束上课',
            3=>'取消预约',
        ];
        return $this->fetch('index',compact('list','shopList','coach','status'));

    }

    //导出预约记录
    public function export(){
        $model = new ReservationModel();
        $model->exportList($this->request->param());
    }

    public function shopList(){
        $shop_user_id = $this->store['user']['shop_user_id'];
        $user_type = $this->store['user']['user_type'];
        $where=[];
        if ($user_type == 2 && $shop_user_id){
            $where['shop_id']=$shop_user_id;
        }elseif ($user_type == 3){
            $coach = CoachModel::detail(['coach_id'=>$shop_user_id]);
            $where['shop_id']=$coach['shop_id'];
        }

        return ShopModel::getAllList($where);
    }

    public function coachList(){
        $model = new CoachModel();
        $user_type = $this->store['user']['user_type'];
        $params = [];
        if ($user_type == 3){
            //教练
            $params['coach_id'] = $this->store['user']['shop_user_id'];
        }elseif ($user_type == 2){
            //门店
            $params['shop_id'] = $this->store['user']['shop_user_id'];
        }
        return $model->getAllList($params);
    }
}